package com.cnhaimei.vod;

import java.util.ArrayList;

import android.app.Activity;
import android.util.Log;

import com.cnhaimei.vod.logic.HomeActivity;


/**
 * Activity管理器 <br>
 * 
 * @author funwell <br>
 * @date 2013-7-27
 * 
 */
public class MyActivityManager {
	private final static MyActivityManager mG = new MyActivityManager();
	private ArrayList<Activity> mActivityList = null;
	
	private MyActivityManager() {
		mActivityList = new ArrayList<Activity>();
	}

	public static MyActivityManager G() {
		return mG;
	}
	
	public void push(Activity activity) {
		if (mActivityList != null) {
			mActivityList.add(activity);
			for (int i = 0; i < mActivityList.size(); i++) {
				Log.e("MyActivityManager", "####### push ######" + mActivityList.get(i).getClass().getName());
			}
		}
	}
	
	public Activity pop() {
		if (mActivityList != null) {
			if (mActivityList.size() > 0) {
				Activity activity = mActivityList.get(mActivityList.size() - 1);
				mActivityList.remove(mActivityList.size() - 1);
				for (int i = 0; i < mActivityList.size(); i++) {
					Log.e("MyActivityManager", "####### pop ######" + mActivityList.get(i).getClass().getName());
				}
				return activity;
			}
		}
		
		return null;
	}
	
	public void goTop() {
		if (mActivityList != null) {
			do {
				Activity activity = pop();
				if (activity != null && activity.getClass() != HomeActivity.class) {
					activity.finish();
				}
				else {
					break;
				}
			} while (true);
		}
	}

}
